/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include <vulkan/vulkan.h>
#include "向量.h"

#include "Vk缓存.h"

#include "../Core/Vk结构声明.h"
#include "底层绘图/S_纹理.h"


#include "S_键值序列容器.h"





VkImageUsageFlags f_get纹理用途(E_纹理用途 用途);


inline VkFormat f_转VK图像格式(E_纹理格式 格式) {
	switch (格式)
	{
	case e_tf_R8:			return VK_FORMAT_R8_SINT;
	case e_tf_RG8:			return VK_FORMAT_R8G8_SINT;
	case e_tf_RGB8:			return VK_FORMAT_R8G8B8_SINT;
	case e_tf_RGBA8:		return VK_FORMAT_R8G8B8A8_SINT;

	case e_tf_R16:			return VK_FORMAT_R16_SINT;
	case e_tf_RG16:			return VK_FORMAT_R16G16_SINT;
	case e_tf_RGB16:		return VK_FORMAT_R16G16B16_SINT;
	case e_tf_RGBA16:		return VK_FORMAT_R16G16B16A16_SINT;

	case e_tf_R32:			return VK_FORMAT_R32_SFLOAT;
	case e_tf_RG32:			return VK_FORMAT_R32G32_SFLOAT;
	case e_tf_RGB32:		return VK_FORMAT_R32G32B32_SFLOAT;
	case e_tf_RGBA32:		return VK_FORMAT_R32G32B32A32_SFLOAT;





	case e_tf_R8U_U:		return VK_FORMAT_R8_UNORM;
	case e_tf_RG8U_U:		return VK_FORMAT_R8G8_UNORM;
	case e_tf_RGB8U_U:		return VK_FORMAT_R8G8B8_UNORM;
	case e_tf_RGBA8U_U:		return VK_FORMAT_R8G8B8A8_UNORM;

	case e_tf_R8U:			return VK_FORMAT_R8_UINT;
	case e_tf_RG8U:			return VK_FORMAT_R8G8_UINT;
	case e_tf_RGB8U:		return VK_FORMAT_R8G8B8_UINT;
	case e_tf_RGBA8U:		return VK_FORMAT_R8G8B8A8_UINT;



	case e_tf_R16U:			return VK_FORMAT_R16_UINT;
	case e_tf_RG16U:		return VK_FORMAT_R16G16_UINT;
	case e_tf_RGB16U:		return VK_FORMAT_R16G16B16_UINT;
	case e_tf_RGBA16U:		return VK_FORMAT_R16G16B16A16_UINT;

	case e_tf_R32U:			return VK_FORMAT_R32_UINT;
	case e_tf_RG32U:		return VK_FORMAT_R32G32_UINT;
	case e_tf_RGB32U:		return VK_FORMAT_R32G32B32_UINT;
	case e_tf_RGBA32U:		return VK_FORMAT_R32G32B32A32_UINT;

	//e_tf_深度纹理:



	case e_tf_D16:			return VK_FORMAT_D16_UNORM_S8_UINT;
	case e_tf_D24:			return VK_FORMAT_D24_UNORM_S8_UINT;
	case e_tf_D32:			return VK_FORMAT_D32_SFLOAT_S8_UINT;
	case e_tf_D64:			return VK_FORMAT_D32_SFLOAT_S8_UINT;
	case e_tf_D32F:			return VK_FORMAT_D32_SFLOAT;
	default:
		break;
	}

	return VK_FORMAT_UNDEFINED;
}




struct S_Vk图像管理 {
	

	~S_Vk图像管理();

	static void			f_释放图像(VkDevice& dev, S_VkImage* image);

	static S_VkImage*	f_创建图像视图(VkDevice& dev, VkImage image, const VkFormat& 格式, uint32 key = 0);

	static S_VkImage*	f_创建纹理图像(S_绘图设备配置& 配置, const VkFormat& 格式, uvec3 size, E_纹理维度类型 类型, uint32 用途, E_MS次数 采样 = E_MS次数::e_MS_1, uint32 key = 0);

	static S_VkImage*	f_创建帧缓存图像(VkDevice& dev, VkPhysicalDeviceMemoryProperties 内存属性, const VkFormat& 格式, uvec3 size, E_MS次数 采样, uint32 key = 0);

	static S_VkImage*	f_创建深度缓存图像(VkDevice& dev, VkPhysicalDeviceMemoryProperties 内存属性, VkPhysicalDeviceProperties 物理设备属性, VkFormat f, uvec3 size, E_MS次数 采样, uint32 key=0);

	
};



VkFormat findSupportedFormat(const VkPhysicalDevice phyDev, 
							const vector<VkFormat>& candidates, 
							VkImageTiling tiling, 
							VkFormatFeatureFlags features);

VkFormat f_findDepthFormat(const VkPhysicalDevice phyDev);


void					f_VkImage_构建(S_VkImage* obj, S_设备环境& ctx);
VkImageMemoryBarrier	f_vk_图像屏障();

void f_releaseImage(VkDevice dev, S_VkImage* obj);



struct S_Vk纹理采样器 : public S_纹理采样器 {
	VkSampler	m_采样器;

	S_Vk纹理采样器(VkDevice& dev, S_纹理采样器创建参数 参数);

};


